<?php

function get_check($value, $name) {
    if ($value > 0) {
        $value = form_checkbox($name, '1', TRUE);
    } else {
        $value = form_checkbox($name, '1');
    }
    return $value;
}

//function get_access($var, $g) {
//    if ($var == 2) {
//        $var = 'Admin';
//    } else {
//        $var = 'User';
//    }
//    return $var;
//}

function get_access($var) {
    $CI = & get_instance();
    $CI->load->model('user_role');
    $level = $CI->user_role->get_access($var);
    return $level;
}

function get_bank($var) {
    $CI = & get_instance();
    $CI->load->model('admin_bank_model');
    $bank = $CI->admin_bank_model->get_bank($var);
    return $bank;
}

function get_admin($var) {
    $CI = & get_instance();
    $CI->load->model('user');
    $level = $CI->user->get_admin($var);
    return $level;
}

function get_show($var, $link, $id) {
    if ($var == 1) {
        $var = "<a href=" . base_url() . $link . "" . $id . "><img src=" . base_url() . "img/detail.png></a>";
    } else {
        $var = '';
    }
    return $var;
}

function get_edit($var, $link, $id) {
    if ($var == 1) {
        $var = "<a href=" . base_url() . $link . "" . $id . "><img src=" . base_url() . "img/edit1.png></a>";
    } else {
        $var = '';
    }
    return $var;
}

function get_delete($var, $link, $id) {
    if ($var == 1) {
        $var = "<a href=" . base_url() . $link . "" . $id . " OnClick=\"return confirm('Are you sure?');\"><img src=" . base_url() . "img/delete.png></a>";
    } else {
        $var = '';
    }
    return $var;
}

function get_delete_jadwal($var, $link, $id) {
    if ($var == 1) {
        $var = "<a href=" . base_url() . $link . "" . $id . " OnClick=\"return confirm('Are you sure?');\"><img src=" . base_url() . "img/delete.png></a>";
    } else {
        $var = '';
    }
    return $var;
}

function get_confirm($var, $link, $id) {
    if ($var == 1) {
        $var = "<a href=" . base_url() . $link . "" . $id . "><img src=" . base_url() . "img/confirm.png></a>";
    } else {
        $var = '';
    }
    return $var;
}

function get_confirm_delete($var, $link, $id) {
    if ($var == 1) {
        $var = "<a href=" . base_url() . $link . "" . $id . "><img src=" . base_url() . "img/confirm.png></a>";
    } else {
        $var = '';
    }
    return $var;
}

function get_add($var, $link) {
    if ($var == 1) {
        $var = "<a href=" . base_url() . $link . "><img src=" . base_url() . "img/add.png></a>";
    } else {
        $var = '';
    }
    return $var;
}

function get_date($date) {
    $date = explode('-', $date);
    $array_hari = array(1 => 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu', 'Minggu');
    $array_bulan = array(1 => 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember');
    $bulan = $array_bulan[$date[1]];
    $tahun = $date[0];
    return $date[2] . ' ' . $bulan . ' ' . $tahun;
}

function get_airport($code) {
    $CI = & get_instance();
    $CI->load->model('rute');
    $level = $CI->rute->get_airport($code);
    return $level;
}

function get_airlines($var) {
    $CI = & get_instance();
    $CI->load->model('airline');
    $maskapai = $CI->airline->get_maskapai($var);
    return $maskapai;
}

function get_image_m($var) {
    $CI = & get_instance();
    $CI->load->model('airline');
    $maskapai = $CI->airline->get_image($var);
    return $maskapai;
}

function get_user($var) {
    $CI = & get_instance();
    $CI->load->model('booking');
    $user = $CI->booking->get_user($var);
    return $user;
}

function get_status($var) {
    if ($var == 0)
        $var = "<font color='red'>Waiting</font>";
    else
        $var = "<font color='green'>Confirm</font>";

    return $var;
}

function get_status_color($var) {
    if ($var == 0)
        $var = "<font color='red'>Waiting</font>";
    elseif ($var == 1)
        $var = "<font color='blue'>Revisi by admin</font>";
    elseif ($var == 2)
        $var = "<font color='blue'>Proses Issued</font>";
    elseif ($var == 4)
        $var = "<font color='Red'>Canceled</font>";
    else
        $var = "<font color='green'>Issued</font>";
    return $var;
}

function get_datetime($date) {
    $date = explode(' ', $date);
    $date1 = $date[0];
    $date2 = $date[1];
    $date1 = explode('-', $date1);
    $array_hari = array(1 => 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu', 'Minggu');
    $array_bulan = array(1 => 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember');
    $bulan = $array_bulan[$date1[1]];
    $tahun = $date[0];
    return $date1[2] . ' ' . $bulan . ' ' . $tahun;
}

function get_money($val) {
    $val = number_format($val, 0, ".", ".");
    return $val;
}

function get_null($var) {
    if ($var == null) {
        $data = 'NA';
    } else {
        $data = $var;
    }
    return $data;
}

function get_jam($jam1, $jam2) {
    $jam1 = explode(':', $jam1);
    $jam2 = explode(':', $jam2);
    $jam = $jam2[0] - $jam1[0];
    $menit = $jam2[1] - $jam1[1];
    return $jam . $menit;
}

function get_alert($link) {
    if ($link == "add")
        $data = "<font color='green'>Berhasil Menambahkan data</font>";
    elseif ($link == "edit")
        $data = "<font color='green'>Berhasil Mengubah data</font>";
    elseif ($link == "delete")
        $data = "<font color='red'>Berhasil Menghapus data</font>";
    else
        $data = "";
    return $data;
}

function get_code($panjang) {
    $karakter = 'ABCDEFGHIJKLMNOPQRSTUPWXYZ1234567890';
    $string = '';
    for ($i = 0; $i < $panjang; $i++) {
        $pos = rand(0, strlen($karakter) - 1);
        $string .= $karakter{$pos};
    }
    return $string;
}

function get_code2($panjang) {
    $karakter = 'ABCDEFGHIJKLMNOPQRSTUPWXYZ1234567890';
    $string = '';
    for ($i = 0; $i < $panjang; $i++) {
        $pos = rand(0, strlen($karakter) - 1);
        $string .= $karakter{$pos};
    }
    $code = array('code' => $string);
    return $code;
}

function get_booking_adult($code) {
    $CI = & get_instance();
    $CI->load->model('booking');
    $level = $CI->booking->get_adult($code);
    return $level;
}

function get_booking_child($code) {
    $CI = & get_instance();
    $CI->load->model('booking');
    $level = $CI->booking->get_child($code);
    return $level;
}

function get_booking_infant($code) {
    $CI = & get_instance();
    $CI->load->model('booking');
    $level = $CI->booking->get_infant($code);
    return $level;
}

function get_month($val) {
    $bulan = array("January", "February", "Maret", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "Desember");
    return $bulan[$val];
}

function get_orangtua($val) {
    $dewasa = array("Dewasa 1", "Dewasa 2", "Dewasa 3", "Dewasa 4", "Dewasa 5");
    return $dewasa[$val];
}

function get_tanggal($date) {
    $date = date('d F Y', strtotime($date));
    return $date;
}

function get_tanggal_1($date) {
    $date = date('d-M-Y', strtotime($date));
    return $date;
}

function get_durasi($depart, $arrive) {
    $depart = explode(':', $depart);
    $arrive = explode(':', $arrive);

    $waktu_sekarang = mktime($depart[0], $depart[1]);
    $waktu_tujuan = mktime($arrive[0], $arrive[1]);

//hitung selisih kedua waktu
    $selisih_waktu = $waktu_tujuan - $waktu_sekarang;

//Untuk menghitung jumlah dalam satuan jam:
    $sisa = $selisih_waktu % 86400;
    $jumlah_jam = floor($sisa / 3600);

//Untuk menghitung jumlah dalam satuan menit:
    $sisa = $sisa % 3600;
    $jumlah_menit = floor($sisa / 60);
    return $jumlah_jam . ":" . $jumlah_menit;
}

function anti_xss($source) {
    $f = stripslashes(strip_tags(htmlspecialchars($source, ENT_QUOTES)));
    return $f;
}

?>
